package com.shop.service;

import com.shop.dao.OrderDao;
import com.shop.dao.StudentDAO;
import com.shop.model.Course;
import com.shop.model.Order;
import com.shop.model.Student;

import java.util.ArrayList;
import java.util.List;

public class OrderService implements IOrderService{
    OrderDao orderDao = new OrderDao();
    IStudentService istudentService = new StudentService();
    ICourseService icourseService = new CourseService();
    public boolean addOrder(String studentId, String courseId, Double total_Price,String starus){
        return orderDao.addOrder(studentId, courseId, total_Price, starus);
    }

    double money =  0;
    //判断余额是否够支付
    public boolean paymoney(String studentId, Double total_Price){//判断余额是否够支付
        Student student = istudentService.search(studentId);
        money = student.getMoney();
        if(money<total_Price){
            return false;
        }else {
            money = money-total_Price;
            return true;
        }
    }
    public boolean updateMoney(String studentId, Double total_money){//更新余额
        return istudentService.updateMoney(studentId, money);
    }
    public boolean updateMoney1(String studentId, Double money){
        return istudentService.updateMoney(studentId,money);//更新余额
    }
    public Boolean updateCourseCapacity(List<String> courseIds, int courseCapacity){//更新课程容量
        return icourseService.updateCourseCapacity(courseIds, courseCapacity);
    }
    public List<String> coursecapacity(List<String> courseIds){//判断所购买的课程容量是否充足
        List<String> courseName = new ArrayList<>();
        for (String courseId : courseIds) {
            if(icourseService.searchCourse1(courseId).getCapacity()<1){
                courseName.add(icourseService.searchCourse1(courseId).getCourseName());
            }
        }
        return courseName;
    }
    public List<Order> queryOrder(String studentId){
        System.out.println("OrderService:47:"+orderDao.queryOrder(studentId).size());//调试
        return orderDao.queryOrder(studentId);
    }

    public List<String> include_course(List<String> courseIds,String studentId){
        List<String> include_course = new ArrayList<>();
        for (String courseId : courseIds) {
            if(!orderDao.include_course(courseId, studentId)){
                include_course.add(icourseService.searchCourse1(courseId).getCourseName());
            }
        }
        return include_course;
    }

    @Override
    public List<Course> getCourses(String studentId) {
        return orderDao.getCourses(studentId);
    }




}
